package com.web.work;

import com.web.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/six")
public class Test6 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
    //6.传入学生id，实现学生删除
    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置内容类型
        resp.setContentType("application/json;charset=utf-8");
        String sql = "delete from student where id=?";
        int id = Integer.parseInt(req.getParameter("id"));
        int i = JDBCUtils.update(sql, id);
        if(i>0){
            resp.getWriter().write("{\"msg\":\"删除成功\"}");
        }else{
            resp.getWriter().write("{\"msg\":\"删除失败\"}");
        }

    }
}
